import Request from '@/axios'
import {Session} from "../../utils/storage";
import router from "@/router";
import useRouterList from "@/store/module/routerList";
import pinia from "@/store";
import {jseEncryptLong} from '../../utils/rsa'
import {AxiosResponse} from "_axios@1.3.4@axios";

/**
 * @description -封装login接口方法
 */
export class UserService {
    /**
     * @description 用户登录
     */
    static async login(params: ILoginParam): Promise<AxiosResponse<IResultData<IUser>>> {
        return Request.post('/user/login', {data: jseEncryptLong(JSON.stringify(params))})
    }

    /**
     * @description 用户退出登陆
     */
    static loginOut(): void {
        Session.clear()
        let useRouterListStore = useRouterList(pinia);
        useRouterListStore.clearAll()
        location.reload(); //清空路由
        router.push({path: '/login'})
    }

    /**
     * @description 获取验证码
     */
    static async getCaptcha(): Promise<AxiosResponse<IResultData<ICaptchaVo>>> {
        return Request.get('/user/getCaptcha')
    }

    /**
     * @description 校验验证码
     */
    static async verifyCaptcha(params: Map<string, Object>): Promise<AxiosResponse<IResultData>> {
        return Request.post('/user/verifyCaptcha', params)
    }
}
